"""
@Project name: 回合制对战游戏

@Author name: jarvis_clark

@Time: 2021/08/22
两个类
角色：名字、性别、血量-HP、攻击力-ATK、防御力-DEF、装备栏-equip_lst
装备有：防弹衣-body armor            增加5点防御力
      精制军刀-saber                增加10点攻击力
      血量增益药剂-HP_BUFF potion    增加10点血量
房间：战斗
"""
"""角色"""

class Character:
    def __init__(self, name, sex):
        self.HP = 100
        self.ATK = 10
        self.DEF = 0
        self.name = name
        self.sex = sex
        self.equip_lst = [0, 0, 0]

    def equipment(self,swich):
        self.swich = swich
        if self.swich == "on":
            while True:
                print("1:防弹衣 2:精致军刀 3:血量增幅药剂")
                choice1 = input("你想要为该名角色穿戴什么装备（退出按任意键）：")
                if choice1 == "1":
                    if self.equip_lst[0] == 0:
                        self.equip_lst[0] = 1
                        self.DEF += 5
                        continue
                    else:
                        print("该角色已经穿戴这件装备，请进行其他操作！")
                        continue
                elif choice1 == "2":
                    if self.equip_lst[1] == 0:
                        self.equip_lst[1] = 1
                        self.ATK += 10
                        continue
                    else:
                        print("该角色已经穿戴这件装备，请进行其他操作！")
                        continue
                elif choice1 == "3":
                    if self.equip_lst[2] == 0:
                        self.equip_lst[2] = 1
                        self.HP += 10
                        continue
                    else:
                        print("该角色已经穿戴这件装备，请进行其他操作！")
                        continue
                else:
                    break
        # print(self.equip_lst)
        #卸下装备
        if self.swich == "off":
            while True:
                print("1:防弹衣 2:精致军刀 3:血量增幅药剂")
                choice2 = input("你想要为该名角色卸下什么装备（退出按任意键）：")
                if choice2 == "1":
                    if self.equip_lst[0] == 1:
                        self.equip_lst[0] = 0
                        self.DEF -= 5
                        continue
                    else:
                        print("该角色未穿戴这件装备，请进行其他操作！")
                        continue
                elif choice2 == "2":
                    if self.equip_lst[1] == 1:
                        self.equip_lst[1] = 0
                        self.ATK -= 10
                        continue
                    else:
                        print("该角色未穿戴这件装备，请进行其他操作！")
                        continue
                elif choice2 == "3":
                    if self.equip_lst[2] == 1:
                        self.equip_lst[2] = 0
                        self.HP -= 10
                        continue
                    else:
                        print("该角色未穿戴这件装备，请进行其他操作！")
                        continue
                else:
                    break
        # print(self.equip_lst)

"""竞技场"""
class Arena:
    def __init__(self, player1, player2):
        self.p1_HP = player1.HP
        self.p1_ATK = player1.ATK
        self.p1_DEF = player1.DEF
        self.P1_name = player1.name

        self.p2_HP = player2.HP
        self.p2_ATK = player2.ATK
        self.p2_DEF = player2.DEF
        self.P2_name = player2.name

    #战斗方法
    def battle(self):
        import random
        import time
        #摇骰子决定谁先攻击
        while True:
            botton1 = input(f"按下任意键为player1: {self.P1_name} 摇骰子")
            a = random.randint(1,6)
            print(f"点数：{a}")
            botton2 = input(f"按下任意键为player2: {self.P2_name} 摇骰子")
            b = random.randint(1,6)
            print(f"点数：{b}")
            if a>b :
                act = 1
                break
            elif a<b:
                act = 2
                break
            else:
                print("点数相同，重新摇骰子")
                continue

        #player1优先攻击
        if act == 1:
            print("战斗开始，ready go！")
            round = 0
            while True:
                round += 1
                print(f"\033[32mROUND{round}\033[0m")
                self.p2_HP -= self.p1_ATK - self.p2_DEF
                print(f"player1: {self.P1_name} 发动了攻击，对player2: {self.P2_name} 造成了 \033[31m{self.p1_ATK - self.p2_DEF}\033[0m 点伤害")
                print(f"player2: {self.P2_name} 当前血量：\033[31m{self.p2_HP}\033[0m, player1: {self.P1_name} 当前血量：\033[31m{self.p1_HP}\033[0m")
                time.sleep(1.2)
                if self.p2_HP <= 0:
                    print(f"the winner is \033[31mplayer1\033[0m:{self.P1_name}")
                    break
                self.p1_HP -= self.p2_ATK - self.p1_DEF
                print(f"\nplayer2: {self.P2_name} 发动了攻击，对player1: {self.P1_name} 造成了 \033[31m{self.p2_ATK - self.p1_DEF}\033[0m 点伤害")
                print(f"player1: {self.P1_name} 当前血量：\033[31m{self.p1_HP}\033[0m, player2: {self.P2_name} 当前血量：\033[31m{self.p2_HP}\033[0m")
                time.sleep(1.2)
                if self.p1_HP <= 0:
                    print(f"the winner is \033[31mplayer2\033[0m:{self.P2_name}")
                    break

        #player2优先攻击
        elif act == 2:
            print("战斗开始，ready go！")
            round = 0
            while True:
                round += 1
                print(f"\033[32mROUND{round}\033[0m")
                self.p1_HP -= self.p2_ATK - self.p1_DEF
                print(f"player2: {self.P2_name} 发动了攻击，对player1: {self.P1_name} 造成了 \033[31m{self.p2_ATK - self.p1_DEF}\033[0m 点伤害")
                print(f"player1: {self.P1_name} 当前血量：\033[31m{self.p1_HP}\033[0m, player2: {self.P2_name} 当前血量：\033[31m{self.p2_HP}\033[0m")
                time.sleep(1.2)
                if self.p1_HP <= 0:
                    print(f"the winner is \033[31mplayer2\033[0m:{self.P2_name}")
                    break
                self.p2_HP -= self.p1_ATK - self.p2_DEF
                print(f"\nplayer1: {self.P1_name} 发动了攻击，对player2: {self.P2_name} 造成了 \033[31m{self.p1_ATK - self.p2_DEF}\033[0m 点伤害")
                print(f"player2: {self.P2_name} 当前血量：\033[31m{self.p2_HP}\033[0m, player1: {self.P1_name} 当前血量：\033[31m{self.p1_HP}\033[0m")
                time.sleep(1.2)
                if self.p2_HP <= 0:
                    print(f"the winner is \033[31mplayer1\033[0m:{self.P1_name}")
                    break




def main():
    import time ,sys, os
    figure_dit = {}
    for i in range(21):
        if i != 10:
            sys.stdout.write("\033[32m==")
        elif i == 10:
            sys.stdout.write("\033[33m勇士与龙之武道场前传\033[32m")
        elif i == 20:
            sys.stdout.write("==\033[0m")
        sys.stdout.flush()
        time.sleep(0.2)

    while True:
        botton1 = input("\n是否开始游戏？（是/否）")
        if botton1 == "是":
            break
        elif botton1 == "否":
            print("您已退出游戏！")
            os._exit(0)
        else:
            print("请规范输入！")
            continue

    global figure_dict
    figure1 = Character("nanfeng", "male")
    figure2 = Character("beihai", "male")
    figure3 = Character("qiuye", "female")
    figure4 = Character("chunshui", "female")
    figure_dict = {"nanfeng":figure1, "beihai":figure2, "qiuye":figure3, "chunshui":figure4}
    global nums
    nums = 0
    while True:
        select_option = input("主菜单：1.查看角色  2.装备设置 3.战斗 4.退出游戏\n执行：")
        if select_option == "1":
            print(f"角色列表：{figure1.name},{figure2.name},{figure3.name},{figure4.name}")
        if select_option == "2":
            swich = input("你想？穿戴装备(输入on)/卸下装备(输入off)")
            if swich != "on" and swich != "off":
                print("请正确操作！")
                continue
            else:
                who = input("对哪名角色操作？")
                if who not in figure_dict:
                    print("没有这个角色！")
                    continue
                else:
                    figure_dict[who].equipment(swich)
        if select_option == "3":
            player1, player2 = input("请选出两位出战角色（以逗号相隔，不得有多于输入）：").split(",")
            if player1 not in figure_dict and player2 not in figure_dict:
                print("某个角色不存在!")
                continue
            else:
                room = Arena(figure_dict[player1],figure_dict[player2])
                room.battle()
        if select_option == "4":
            print("您已退出游戏！")
            os._exit(0)
if __name__ == "__main__":
    main()
